﻿$(async function () {
    await window.ris.initialize();
    window.enableAMISDebug = true;
    var form;
    let formData;
    let amisJosn;
    let ris = window.ris;

    $(".page-container .report-bar-button").on("click", () => {
        location.href = "/mobile/exam";
    })

    Promise.all([$.get(`/api/home/get-home-view-mobile`), $.get(`/api/home/get-user-info?stationCode=`)]).then(function (res) {
        amisJosn = JSON.parse(res[0].data.amisJson);

        let permissions = amisJosn.data.permissions;

        // 权限检测
        Object.keys(permissions).forEach(key => {
            if (ris.permissions.some(item => item === key)) {
                permissions[key] = true;
            }
        });

        amisJosn.data = { ...amisJosn.data, ...{ userName: res[1].userName, departmentName: res[1].departmentName, permissions: permissions } }

        var options = {
            $element: $("#main"),
            view: amisJosn,
            formData: {},
        }
        form = $("#main").amisForm(options);
    });


})
